package com.hspedu.interface_;

public class InterfacePolyArr {
    public static void main(String[] args) {
        //多态数组 -> 接口类型的数组
        MyUsb [] myUsb = new MyUsb[2];
        myUsb[0] = new Phone_();
        myUsb[1] = new Camera_();
        for (int i = 0; i < myUsb.length; i++) {
            myUsb[i].start();//动态绑定
            myUsb[i].end();//动态绑定
            if (myUsb[i] instanceof Phone_){//判断它的运行类型是什么
                ((Phone_)myUsb[i]).cal();
            }
            System.out.println();
        }

    }

}

interface MyUsb{
    int n1 = 100;
    void start();
    void end();
}

class Phone_ implements MyUsb{
    public int n2 = 200;
    @Override
    public void start() {
        System.out.println("手机连接上了..");
    }

    @Override
    public void end() {
        System.out.println("手机断开了..");
    }

    public void cal(){
        System.out.println("我是手机..");
    }
}

class Camera_ implements MyUsb{
    public int n1 = 200;
    @Override
    public void start() {
        System.out.println("相机连接上了..");
    }

    @Override
    public void end() {
        System.out.println("相机断开了..");
    }


}